var phoneVal = /^(13|15|18|17|14|16|19)[0-9]{9}$/;
var emailVal = /^([0-9A-Za-z\-_\.]+)@([0-9a-z]+\.[a-z]{2,3}(\.[a-z]{2})?)$/;
var verify = /^\d{4}$/;
var isNull = /^[\s]{0,}$/;
var wait = 60;
var codeVal=/^[A-Za-z0-9]{0,20}$/;

function phoneCheck() {
	var ipt = $("input[name='phone']");
	var val = ipt.val();
	var p =$("#moble-msg"); 
	 if(val==""||val==null){
         layer.tips(_error_global.js_enterEmailNum, '#moble', {tips: 3});
         return false;
     }
		if (!emailVal.test(val)) {
			layer.tips(_error_global.js_emailNumError, '#moble', {tips: 3});
			return false;
		}
		var data={"phone":ipt.val()};
		$.ajax({
			type:"post",
			dataType:"html",
			url:_nURL,
			data:data,
			success:function(data){
				if (data.trim() == 'true') {
					 layer.tips(_error_global.js_phoneNumExist, '#moble', {tips:3});
					return false;
				}}});
		return true;
}

function txverifyCheck() {
	var val = $("input[name='txverifyCode']").val();
	var p = $("#verify");
	if (isNull.test(val)) {
		layer.tips(_error_global.js_captchaNotNull, '#verify', {tips:3});
		return false;
	} else if (!verify.test(val)) {
		layer.tips(_error_global.js_captchaError, '#verify', {tips:3});
		return false;
	}
	return true;
}

 function sendCode(evn){
	var ipt = $("input[name='phone']");
	var tx = $("input[name='txverifyCode']").val();
	var val = ipt.val();
	var p =$("#moble-msg"); 
	 if(val==""||val==null){
       layer.tips(_error_global.js_enterEmailNum, '#moble', {tips: 3});
       return false;
   }
		if (!emailVal.test(val)) {
			layer.tips(_error_global.js_emailNumError, '#moble', {tips: 3});
			return false;
		}
	if (isNull.test(tx)) {
		layer.tips(_error_global.js_captchaNotNull, '#verify', {tips:3});
		return false;
	} else if (!verify.test(tx)) {
		layer.tips(_error_global.js_captchaError, '#verify', {tips:3});
		return false;
	}
	sendclick(evn);
	var datatx={"txverifyCode":tx};
	$.ajax({
		type:"post",
		dataType:"html",
		url:_tx_url,
		data:datatx,
		success:function(data){
			if(data==1){
				var data={"phone":val,"type":"REGISTER"};
				$.ajax({
					type:"post",
					dataType:"html",
					url:_cUrl,
					data:data,
					success:function(data){
						var ct = eval('('+data+')');
						if(ct.length>0){
							if(ct[0].num == 2){
							}
							layer.tips(ct[0].msg.indexOf("err_")!=-1?eval("_error_global."+ct[0].msg):ct[0].msg, '#regBtn', {tips: 2});
							return false;
						}
					}
				});
			}else{	
				layer.tips(data, '#verify', {tips: 2});
				return false;
			}
			}
	});
}
 
 function sendclick(evn){
	 var obj = $('#regBtn');
	 if (wait == 0) {
			obj.val(_error_global.js_getCaptcha);
            obj.css('backgroundColor', '#0d66bf');
			wait = 60;
		} else {
			 obj.css('backgroundColor', '#999B9C');
             obj.val(wait + _error_global.js_sendAgain);
             wait--;
			setTimeout(function() {
				sendclick(evn);
			},
			1000);
		}
	}

 function dxverifyCheck() {
		var val = $("input[name='dxverifyCode']").val();
		var p = $("#verify");
		if (isNull.test(val)) {
			layer.tips(_error_global.js_smsVerificationCodeNotNull, '#moble_verify', {tips:3});
			return false;
		} else if (!verify.test(val)) {
			layer.tips(_error_global.js_smsVerificationCodeError, '#moble_verify', {tips:3});
			return false;
		}
		return true;
	}

 function passwordCheck() {
		var ipt = $("input[name='password']");
		var val = ipt.val();
		if (isNull.test(val)) {
			layer.tips(_error_global.js_passwordCannotNull, '#password', {tips:3});
			return false;
		} else if (val.length<6 || val.length >16) {
			layer.tips(_error_global.js_passwordReg, '#password', {tips:3});
			return false;
		}
		return true;
	}
	
 function codeCheck() {
		var ipt = $("input[name='code']");
		var val = ipt.val();
		if (!codeVal.test(val)) {
			layer.tips(_error_global.register_invitationCodeReg, '#code', {tips:3});
			return false;
		}
		return true;
	}
 function rePasswordCheck() {
		var ipt = $("input[name='password']");
		var _ipt = $("input[name='newPassword']");
		var val = ipt.val();
		var _val = _ipt.val();
		if (isNull.test(ipt.val())) {
			layer.tips(_error_global.js_enterPwd, '#repassword', {tips:3});
			return false;
		} else if (isNull.test(_val)) {
			layer.tips(_error_global.js_repeatNotPwd, '#repassword', {tips:3});
			return false;
		} else if (_val != val) {
			layer.tips(_error_global.js_passwordNotSame, '#repassword', {tips:3});
			return false;
		}
		return true;
	}
 
 function onSubmit()
 {
	
 	if (phoneCheck()&&txverifyCheck()&&dxverifyCheck()&&passwordCheck()&&rePasswordCheck()&&codeCheck()){
 		return true;
 	}
 	return false;
 }
 
    function registerAgreement(){
        layer.open({
            type:2,
            skin:'layui-layer-rim', //加上边框
            area:['800px','600px'], //宽高
            title:'注册协议', //不显示标题
            content:xy_url
        });
    }